//////////////////////////////////////////////////////////////////////////
// route module
// author   : zhangpeng
// date     : 2012-2-6
//////////////////////////////////////////////////////////////////////////
var path = require("path");
function route(handle, pathName, res, req) {
    console.log("about to route a reqest for " + pathName);
    var suffix = path.extname(req.url);
    //console.log("suffix : " + suffix);
    var resHeadDone = true;
    switch(suffix) {
        case ".html":
        case ".js":
        case ".css":
        case ".gif":
        case ".png":
        case ".jpg":
        case ".json":
            break;
        default:
            resHeadDone = false;
            if (typeof handle[pathName] === "function") {
                handle[pathName](res, req);
            } else {
                if (pathName == "/favicon.ico") {

                } else{
                    //maybe put some handle fun here.
                    handle["staticServer"](pathName, res, req);
                    //handle["agentKaixin001"](pathName, res, req);
                }
                /*
                console.log("no request handler for " + pathName);
                res.writeHead(404, { "Content-Type": "text/plain" });
                res.write("404 Not found");
                res.end();
                */
            }
            break;
    }
    if (resHeadDone) {
        handle["staticPage"](pathName, res, req);
        /*
        res.writeHead(200, {"Content-Type" : "image/jpeg"});

        res.end();
        */
    }
}
exports.route = route;